package com.magist.manage.email.service.impl;

import com.magist.core.util.DateUtil;
import com.magist.core.util.PrintOutUtil;
import com.magist.core.util.SendEmailUtils;
import com.magist.manage.copyrights.entity.SupplyInfo;
import com.magist.manage.email.service.EmailSender;
import com.magist.manage.enums.OrganizationTypeEnum;
import com.magist.manage.enums.SupplyLevelEnum;
import com.magist.manage.enums.SupplyStatusEnum;
import com.magist.manage.enums.SupplyTypeEnum;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Component
public class SupplyInfoEmailSenderImpl implements EmailSender<SupplyInfo> {

    @Override
    public void sendEmail(List<SupplyInfo> datas, String subject, String to) {
        if (!CollectionUtils.isEmpty(datas)) {
            StringBuilder content = new StringBuilder(
                    "<table border=\"1\" cellspacing=\"0\">" +
                    "<caption><h1>" + subject + "</h1></caption>" +
                    "<thead><tr>" +
                    "<th>ID</th>" +
                    "<th>供应商简称</th>" +
                    "<th>机构类型</th>" +
                    "<th>供应商类型</th>" +
                    "<th>评级</th>" +
                    "<th>合作状态</th>" +
                    "<th>对接人</th>" +
                    "<th>操作人</th>" +
                    "<th>修改时间</th>" +
//                    "<th>操作</th>" +
                    "</tr></thead>");
            datas.forEach(supplyInfo -> {

                content.append("<tr><td>" + supplyInfo.getShowId() + "</td>");
                content.append("<td>" + PrintOutUtil.printOut(supplyInfo.getNickName()) + "</td>");
                content.append("<td>" + OrganizationTypeEnum.getByCode(supplyInfo.getOrganizationType()).getDesc() + "</td>");
                content.append("<td>" + SupplyTypeEnum.getByCode(supplyInfo.getSupplyType()).getDesc() + "</td>");
                content.append("<td>" + SupplyLevelEnum.getByCode(supplyInfo.getSupplyLevel()).getDesc() + "</td>");
                content.append("<td>" + SupplyStatusEnum.getByCode(supplyInfo.getStatus()).getDesc() + "</td>");
                content.append("<td>" + PrintOutUtil.printOut(supplyInfo.getPersonName()) + "</td>");
                content.append("<td>" +  PrintOutUtil.printOut(supplyInfo.getModifier()) + "</td>");
                content.append("<td>" + DateUtil.format(supplyInfo.getModifyTime(),DateUtil.yyyy_MM_dd_HH_mm_ss) + "</td>");
//                content.append("<td><a href=\"http://kada.dumeiweiping.com/index.html#/supplyInfo/eidt?id=" + supplyInfo.getId() + "\">" + "去操作" + "</a></td></tr>");
            });
            content.append("</table>");
            SendEmailUtils.sendEmail(subject, content.toString(), to);
        }


    }
}
